package com.yeyouluo.partition;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class PartitionMapper extends Mapper<LongWritable, Text, Text, PartitionBean> {
    private Text k = new Text();
    private PartitionBean partitionBean = new PartitionBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] fields = line.split("\t");
        partitionBean.setLogId(fields[0]);
        partitionBean.setDeviceId(fields[1]);
        partitionBean.setAppKey(fields[2]);
        partitionBean.setIpAddr(fields[3]);
        partitionBean.setSelfDuration(Long.parseLong(fields[4]));
        partitionBean.setThirdPartDuration(Long.parseLong(fields[5]));
        partitionBean.setStatusCode(Long.parseLong(fields[6]));

        k.set(fields[2]);
        context.write(k, partitionBean);
    }
}
